
<?php
include_once(dirname(__FILE__) . "/model/nms_alarm_model.php");
include_once(dirname(__FILE__) . "/libs/nms_html_scripts.php"); 
include_once(dirname(__FILE__) . "/libs/nms_html_views.php");
include_once(dirname(__FILE__) ."/../../lib/data_query.php");
include_once (dirname(__FILE__) . "/model/nms_system_model.php");
function draw_alarm_view(){
	/* 
	 * add script using function alarm
	 * */
	html_master_script_filter();
	html_master_script_checkall();
	html_alarm_script();
	?>
	<script type="text/javascript">
	<!--
	function pauseaudio(Eaudio){
		var audio = document.getElementById(Eaudio);
		audio.pause();
	}
	// function play audio
	//audio element\
	function playnow(audioElm){
		audioElm.play();
	}
	function playAudio(n1,src1,n3,src3,n4,src4){
		var duration1=0;
		var duration2=0;
		var duration3=0;
		var duration4=0;
		//time to play in oder
		var time = 0;
		//time delay between two sound
		var tDelay=500;
		// set default do get duration
		audioElm.src ="upload/defaultSound1.mp3";
		// get duration sound of device down
		
		if(n1>0){
			audioElm1.src = src1;
			audioElm1.addEventListener("loadedmetadata", function(_event) {
				duration1 = audioElm1.duration;
			});
		}

		// get duration sound of interface down
		if(n3>0){
			audioElm3.src = src3;
			audioElm3.addEventListener("loadedmetadata", function(_event) {
				duration3 = audioElm3.duration;
			});
		}
		// get duration sound of interface up
		if(n4>0){
			audioElm4.src = src4;
			audioElm4.addEventListener("loadedmetadata", function(_event) {
				duration4 = audioElm4.duration;
			});
		}
		// start play sound
		audioElm.addEventListener("loadeddata", setTimeout(function(_event) {
			//play sound 1
			if(src1 != "upload/No Sound"){
				for(var i=1;i<=n1;i++){
					setTimeout('playnow(audioElm1)',time);
					time = time + (duration1*1000)+tDelay;
				}
			}
			//play sound 3
			if(src1 != "upload/No Sound"){
				for(var i=1;i<=n3;i++){
					setTimeout('playnow(audioElm3)',time);
					time = time + (duration3*1000)+tDelay;
				}
			}
			//play sound 4
			if(src1 != "upload/No Sound"){
				for(var i=1;i<=n4;i++){
					setTimeout('playnow(audioElm4)',time);
					time = time + (duration4*1000)+tDelay;
				}
			}
		},500));
		
	} 
	function updatehostsound(re,id){
		document.location.href = "?run=alarm&id="+re+"&update="+id;
	}
	//-->
	</script>
	<audio id="audio"> Browser not supported</audio>
	<audio id="audio1"> Browser not supported</audio>
	<audio id="audio2"> Browser not supported</audio>
	<audio id="audio3"> Browser not supported</audio>
	<audio id="audio4"> Browser not supported</audio>
	<script type="text/javascript">
<!--

//-->
var audioElm = document.getElementById("audio");
var audioElm1 = document.getElementById("audio1");//audio element\
var audioElm2 = document.getElementById("audio2");//audio element\
var audioElm3 = document.getElementById("audio3");//audio element\
var audioElm4 = document.getElementById("audio4");//audio element\
</script>
	<?php 
	/*
	 * draw host warring
	 */
	$errorhost = db_fetch_cell('Select count(*) from host where status != 3');
	if($errorhost>0){
		draw_host_warring();
	}
	/*
	 *	draw alarm filter
	 * */
	draw_alarm_filter();
	/*
	 * functions main php alarm
	 * */
		
	//default page
	$display =25;
	//begin get query string from url to decide what relevant data
		$sql_where  ="";
		/* if the user pushed the 'clear' button */
		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["host_id"]);
			unset($_REQUEST["search"]);
			unset($_REQUEST["filter"]);
			$_REQUEST["id"]=0;
			$_REQUEST['run']='alarm';
			
		}
		if(!empty($_REQUEST['id'])){
			$id=$_REQUEST['id'];
		}else{
			$id=0;
		}
		/* get value from action filter host*/
		if (!empty($_GET['host_id'])) {	
			if($_GET['host_id']=='null')
			{
			$sql_where.="";	
			}else{
			$sql_where .="and a.host_id =".$_GET['host_id']."";
			}
		}
		/* get value from action filter status*/
		if(isset($_REQUEST['filter'])){
			if($_REQUEST['filter']=="All"){
			$sql_where .="";
			}
			if($_REQUEST['filter']=="Up"){
			$sql_where.=" and a.nms_status='Up'and a.nms_pause='1'and a.issound='1'";
			}
			if($_REQUEST['filter']=="Down"){
				$sql_where.=" and a.nms_status='Down'and a.nms_pause='1'";
			}
			if($_REQUEST['filter']=="Pause"){
				$sql_where.=" and a.nms_pause='0'";
			}
			if($_REQUEST['filter']=="Unknown"){
				$sql_where.=" and a.nms_status='Unknown' and a.nms_pause='1'";
			}
			if($_REQUEST['filter']=="Normal"){
				$sql_where.=" and a.nms_pause='1' and a.nms_status='Up' and a.issound ='0'";
			}
			if($_REQUEST['filter']=="Change"){
				$sql_where.=" and (((a.issound='1' and (a.nms_status='Up' or a.nms_status='Unknown')) or a.nms_status ='Down') and a.nms_pause='1')";
			}
		}
		/* get value from action search information*/
		if (!empty($_REQUEST['search'])) {
			$research=trim($_REQUEST['search']);
			$sql_where.=" and (a.snmp_index like '%".$research."%' or c.description like '%".$research."%' or c.hostname like '%".$research."%' or CONCAT(c.description,' ','(',c.hostname,')') like '%".$research."%'
		 				or CONCAT('(',interface_name,')','\t',interface_alias) like '%".$research."%' or a.interface_name like '%".$research."%' or a.interface_alias like '%".$research."%')";
		}
		/* set defaut value when click alarm*/
		if(($_REQUEST['run']=="alarm") and isset($_REQUEST['id']) and empty($_REQUEST['filter']) and empty($_REQUEST['host_id']) and empty($_REQUEST['search']) )
		{
			$sql_where.=" and (((a.issound='1' and (a.nms_status='Up' or a.nms_status='Unknown')) or a.nms_status ='Down') and a.nms_pause='1')";
		}
		/* Get total interface_id from table plugin_nms_interface*/
		$query = "SELECT count(a.interface_id)
					FROM plugin_nms_interface a, host c
					where a.host_id = c.id ".$sql_where."";
		$record =db_fetch_cell($query);
		if ($record > $display){
			$page = ceil($record/$display);
		}else {
			$page = 1;
		}
		// update sound 
		if(isset($_REQUEST["update"])){
			update_sound_device($_REQUEST["update"]);
		}
	$start = $id;
	$current = ($start/$display)+1;
	$next = $start + $display;
	$previous = $start - $display;
	$last = ($page - 1)*$display;
	if ($current >= 11) {
		$start_page = $current - 5;
		if ($page > $current + 5)
			$end_page = $current + 5;
		else if ($current <= $page && $current > $page - 10) {
			$start_page = $page - 10;
			$end_page = $page;
		} else {
			$end_page = $page;
		}
	} else {
		$start_page = 1;
		if ($page > 11)
			$end_page = 11;
		else
			$end_page = $page;
	}
	$querydata="SELECT a.interface_id as id,a.nms_pause as nms_pause,a.snmp_index as snmp_index ,a.host_id as host_id, a.interface_name as descrip , a.interface_alias as alias , a.nms_status as nms_status, b.nms_time as nms_time ,CONCAT_WS('',c.description,' (',c.hostname,')') as host_name,b.user_active as user,CONCAT('(',a.interface_name,')','\t',a.interface_alias) as interface_des
					FROM plugin_nms_interface a , (select * from plugin_nms_log order by nms_time desc) b , host c
					where a.interface_id=b.interface_id and a.nms_status = b.nms_status and a.host_id = c.id and a.present =1 ".$sql_where."
					group by a.interface_id order by a.nms_pause DESC,a.nms_status,a.issound DESC ,b.nms_time DESC limit $start,$display";
	
	/*
	 * draw showlog when click showlog
	 * */
	
	if(!empty($_REQUEST['tab'])){
		if($_REQUEST['tab']=="showlog"){
			$id_show = $_REQUEST['id_show'];
			update_log($id_show);
			update_isound($id_show);
			draw_showlog_views($id_show);
		}
	}
	/*
	 * draw alarm nav
	 * */
	draw_alarm_nav($page,$previous,$display,$next,$last,$current,$start_page,$end_page);
	

	if (empty($_GET['filter'])) {
		$status="Change";
	}
	else{
		$status =  $_GET['filter'];
	}
	if (empty($_GET['host_id'])) {
		$host_id="";
	}
	else{
		$host_id =  $_GET['host_id'];
	}
	if (empty($_GET['search'])) {
		$search="";
	}
	else{
		$search =  $_GET['search'];
	}
	    		//build where status query
	if(isset($_GET['filter']) or isset($_GET['host_id']) or isset($_GET['search'])){
	    	$base_url = "nms.php?run=alarm&filter=".$status."&host_id=".$host_id."&search=".$search."";
	   }else{
	       	$base_url="nms.php?run=alarm";
	}
	$url= "$base_url&id=".$_REQUEST['id']."";
	/*
	 * draw alam table
	 * */
	draw_alarm_table($querydata,$url);
	
   	if (isset($_REQUEST['search'])) {
    	?>
    				<script >
    					var tmp = $('#id_master_table tr').removeHighlight().highlight('<?php echo trim($_GET['search']) ?>');
    					alert(test);
    					$('#id_master_table').empty();
    					$('#id_master_table').html(test);
    				</script>
   	<?php 
    }
    /*
     * draw alarm nav
     * */
	draw_alarm_nav($page,$previous,$display,$next,$last,$current,$start_page,$end_page);
	/*
	 * draw alarm footer
	 * */
	
	draw_alarm_footer();
	html_script_reload();
	
	}
function draw_alarm_filter(){
	html_master_header_start("Host Load Filter");
?>
<!--center-->
    		<table border="0">
    			<tr>
	    		<!-- Status filter -->
	    			<td >Status:</td>
	    			<td>
		    			<select onchange="val()"  id="id_status_alarm" style="width: 120px;">
		    				<option value="Change">Change Status</option>
				        	<option value="All">All</option>
				            <option value="Up">Up</option>
				            <option value="Down">Down</option>
				            <option value="Pause">Pause</option>
				            <option value="Normal">Normal</option>
				            <option value="Unknown">Unknown</option>
		        		</select>
		        	</td>
	    			<!--  -->
	    			<!-- Devices filter -->
	    			<td >Device:</td>
		    		<td>
		    			<select data-placeholder="Choose a device..." id="id_host_alarm">
		    				<option value="">Any</option>
			        		<?php
	     					 $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host where description !='Localhost' order by description,hostname");
	     					 if (sizeof($hosts) > 0) {
						     foreach($hosts as $set) {
						     echo "<option value='" . $set["id"] . "'";if(isset($_REQUEST["host_id"])){if($_REQUEST["host_id"] == $set["id"]){echo "selected";}}; echo ">" . htmlspecialchars($set["name"]) . "</option>\n";
						     }
						     }
	   						?>
		        		</select>
		        		<script type="text/javascript">
							$("#id_host_alarm").chosen({
							search_contains: true,
							no_results_text:"Oops, nothing found!"});
							$("#id_host_alarm").on('change',function(){
							 	//get current selected value of combobox
							 	var deviceValue = $(this).val();
							 	var statusValue = $("#id_status_alarm").val();
							 	var searchFilter = $("#id_search").val();
							 	//build query string
							 	var queryString = "run=alarm&filter="+statusValue+"&host_id="+deviceValue+"&search="+searchFilter+"&id=0";
							 	document.location.href = "?"+queryString;
							});
 					  	</script>
		    		</td>
	    			<!--  -->
	    			<!-- Button export -->
	  				<!-- Search -->
					<td>Search</td>
					<td colspan="3" scope="col">
	    				<input id="id_search" type="search" onkeypress="keydown(event)"/>
	    			</td>
	    			<td>&nbsp;</td>
			    	<td>
			    		<input id="btnGo" type="button" value="Go" ;">
			    	</td>
			    	<td>&nbsp;</td>
			    	<td>
			    		<input id="btnClear" type="submit" name="clear_x" value="Clear" title="Clear Filters">
			    	</td>
			    	<td>&nbsp;</td>
					<td>
						<input id="btnRefresh" type="button" value="Refresh" onClick="window.location.reload( true );">
					</td>
					<td>&nbsp;</td>
					<?php
						$up= "SELECT count(a.interface_id)
						FROM plugin_nms_interface a ,host b
						where a.nms_status ='Up' and a.nms_pause='1' and a.issound='1' and a.host_id = b.id";
						$nomal= "SELECT count(a.interface_id)
						FROM plugin_nms_interface a ,host b
						where a.nms_status ='Up' and a.nms_pause='1' and a.issound='0' and a.host_id = b.id";
						$down= "SELECT count(a.interface_id)
						FROM plugin_nms_interface a ,host b
						where a.nms_status ='Down'and a.nms_pause='1' and a.host_id = b.id";
						$pause= "SELECT count(a.interface_id)
						FROM plugin_nms_interface a ,host b
						where a.nms_pause='0' and a.host_id = b.id";
						$unknown= "SELECT count(a.interface_id)
						FROM plugin_nms_interface a ,host b
						where a.nms_status='Unknown'and a.nms_pause='1' and a.host_id = b.id and a.present = 1";
						$sumup =db_fetch_cell($up);
						$sumdown =db_fetch_cell($down);
						$sumpause =db_fetch_cell($pause);
						$sumnomal =db_fetch_cell($nomal);
						$sumunknown =db_fetch_cell($unknown);
					?>
				   <td class="cls_alarm_color_up" align="center">
				     <a href="nms.php?run=alarm&id=0&filter=Up" ><?php echo $sumup;?></td>
					<td><h4>Up</h4></td>
					<td>&nbsp;</td>
				    <td class="cls_alarm_color_down" align="center">
				    <a href="nms.php?run=alarm&id=0&filter=Down" ><?php echo $sumdown;?></td>
					<td><h4>Down</h4></td>	
					<td>&nbsp;</td>
					<td class="cls_alarm_color_pause" align="center"><div>
					<a href="nms.php?run=alarm&id=0&filter=Pause" ><?php echo $sumpause;?></div></td>
					<td><h4>Pause</h4></td>
					<td>&nbsp;</td>
					<td class="cls_alarm_color_normal" align="center"><div>
					<a href="nms.php?run=alarm&id=0&filter=Normal" ><?php echo $sumnomal;?></div></td>
					<td><h4>Normal</h4></td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td class="cls_alarm_color_unknow" align="center"><div>
					<a href="nms.php?run=alarm&id=0&filter=Unknown" ><?php echo $sumunknown;?></div></td>
					<td><h4>Unknown</h4></td>
					<td>&nbsp;</td>
			    </tr>
    		</table> 			
	<?php
		html_master_header_end();
}
function draw_alarm_nav($page,$previous,$display,$next,$last,$current,$start_page,$end_page){
		html_master_nav_page_start();
		if (empty($_GET['filter'])) {
			$status="Change";
		}
		else{
			$status =  $_GET['filter'];
		}
		if (empty($_GET['host_id'])) {
			$host_id="";
		}
		else{
			$host_id =  $_GET['host_id'];
		}
		if (empty($_GET['search'])) {
			$search="";
		}
		else{
			$search =  $_GET['search'];
		}
		?>
    <script type="text/javascript">
    	$("#id_status_alarm").val('<?php echo $status;?>');
    	$("#id_host_alarm").val('<?php echo $host_id;?>');
    	$("#id_search").val('<?php echo $search;?>');
    </script>
    <?php 
    		if (isset($_REQUEST["btnClear"])) {
		    	unset($_REQUEST["#id_search"]);
		    	unset($_REQUEST["id_host_alarm"]);
		    	unset($_REQUEST["id_status_alarm"]);
    		}
    		//build where status query
    		if(isset($_GET['filter']) or isset($_GET['host_id']) or isset($_GET['search'])){
    		 	$base_url = "nms.php?run=alarm&filter=".$status."&host_id=".$host_id."&search=".$search."";
    		 }
    		 else{
       			$base_url="nms.php?run=alarm";
       		}
	  	   	if($page > 1) {
	       	if ($current > 1) {
	            echo "<li><a href='$base_url&id=0'>First</a></li>";
	            echo "<li><a href='$base_url&id=$previous'>Previous</a></li>";
	       	} 
	       for ($i = $start_page; $i <= $end_page; $i++) {
	 
	            if ($current == $i)
	                echo "<li class='current'>$i</li>";
	            else
	                echo "<li><a href='$base_url&id=".($display*($i-1))."'>$i</a></li>";
	        }
	      	if ($current < $page) {
	            echo "<li><a href='$base_url&id=$next'>Next</a></li>";
	            echo "<li><a href='$base_url&id=$last'>Last</a></li>";
	           } 
	     	}	     
		html_master_nav_page_end();
	}
function draw_alarm_table($querydata,$url){
		$result = db_fetch_assoc($querydata);
		$base_url_log="$url&tab=showlog";
	?>
		<form action="<?php echo $url?>" method ="post"enctype="multipart/form-data" id ="id_check_table_all">
			<!-- phan table -->
			<div id="id_master_table">
			<table width="100%" border="0" align="center">
			<tr class="cls_master_table_title" align="center">
			<th width="3%" scope="col">No</th>
			<th width="3%" scope="col">Index</th>
			<th width="20%" scope="col">Host name</th>
			<th width="30%" scope="col">Interface</th>
			<th width="6%" scope="col">Status</th>
			<th width="13%" scope="col">Time</th>
			<th width="6%" scope="col" align="center">Show Log</th>
			<th width="6%" scope="col">User</th>
			<th width="2%" >
			<input type="checkbox" name='checkall' id='nms-checkbox-checkall' onclick='checkedAll("id_check_table_all");'/>
			</th>
			</tr>
					<!-- do du lieu vao bang -->
   					<?php 
   					$check_status=false;
   					if(isset($_REQUEST['filter'])){
						if($_REQUEST['filter']=="Change"){
   						$check_status = true;
   						}
   					}
   					if($check_status ==true or ($_REQUEST['run']=="alarm") and isset($_REQUEST['id']) and empty($_REQUEST['filter']) and empty($_REQUEST['host_id']) and empty($_REQUEST['search'])){
   					$ndown = db_fetch_cell('select count(*) from plugin_nms_interface
											Where nms_status = "down"
												and issound = "1"
												and nms_pause = "1"');
					$nddown = db_fetch_cell('select count(*) from host
											Where status = 1
												and warning= 1');

   					$nup = db_fetch_cell('select count(*) from plugin_nms_interface
											Where nms_status = "up"
												and issound = "1"
												and nms_pause = "1"');
   					
   					$scrdown = db_fetch_cell('select sound_name from plugin_nms_setting
													where sound_down = 1');
					$scrddown = db_fetch_cell('select sound_name from plugin_nms_setting
													where device_down = 1');
   					$scrup = db_fetch_cell('select sound_name from plugin_nms_setting
													where sound_up = 1');
   					echo
   					'<script type = "text/javascript">
							playAudio('.$nddown.',"upload/"+"'.$scrddown.'",'.$ndown.',"upload/"+"'.$scrdown.'",'.$nup.',"upload/"+"'.$scrup.'");
						</script>';
   					}
					foreach($result as $set) {
					?>
					<!-- thay doi mau cho cac trang thai trong bang -->
					<tr <?php
					 if($set['nms_status']=='Down'& $set['user']==null & $set['nms_pause']==1) {echo 'data-status ="1" class="mautrangthaivuaDown"';}
					 elseif($set['nms_status']=='Down'& $set['user']!= null & $set['nms_pause']==1){echo 'data-status ="2" class="mautrangthaiDown"';}
					 elseif($set['nms_status']=='Up'& $set['user']==null & $set['nms_pause']==1){echo 'data-status ="3" class="mautrangthaiUp"';}
					 elseif($set['nms_status']=='Up'& $set['user']!=null & $set['nms_pause']==1){echo 'data-status ="4" class="mautrangthaiNomal"';}
					 elseif($set['nms_status']=='Unknown'& $set['nms_pause']==1){echo 'data-status ="6" class="mautrangthaiUnk"';}
					 elseif($set['nms_pause']==0) {echo 'data-status ="5" class="mautrangthaiPause"';}?>>
					  	<td align="center" id="getpost">&nbsp;<?php echo $set['id']?></td>
					    <td align="center">&nbsp;<?php echo $set['snmp_index']?></td>
					    <td >&nbsp;<?php echo $set['host_name']?></td>
					    <td>&nbsp;<?php echo $set['interface_des']?></td> 
					    <td align="center">&nbsp;<?php echo $set['nms_status']?></td>
					    <td align="center">&nbsp;<?php  echo $set['nms_time'] ?></td>				    
	    				<td align="center"> <a href="<?php echo $base_url_log?>&id_show=<?php echo$set['id']?>" class='cls-showlog' >Show-Log</a>
						</td>
	    				<td align="center">&nbsp;<?php echo  $set['user']?></td>		
						 <td align="center">&nbsp;<input type="checkbox" value="<? echo $set['id']; ?>"id="pause[]" name="pause[]" class='cls-alarm-table-checkbox'/>
	  				</tr>
				<?php		   
				}
				?>
			</table>
		</div>
<?php 
	}
function draw_alarm_footer(){	
	html_master_footer_start();
?>
		<input class="action_pause"  type = "submit" name = "save" value="Go"  onclick="return confirm('Are you sure you want to implement action?')">
				<select name= "action"  class="action_cancel" >
					<option value="Active">Ack</option>
					<?php 
					$check_pause = system_set_access_2();
					if($check_pause==true){
					?>
					<option value="Pause">Pause</option>
					<option value="Resume">UnPause</option>	
					<?php 
					}?>
				</select>
		<h4 class="action">Action:</h4>
		<div class="countdown_time"  >
				<h3><div id="Timerefresh0">Day: </div></h3>
				<h3><div id ="countdown_time1"></div></h3>
				<h3><div id="Timerefresh">Refresh time: </div></h3>
				<h3><div id ="countdown_time2"></div></h3>
		</div>
<?php
		html_alarm_script_time();
		html_master_footer_end();
	}
function draw_host_warring(){
?>
	<div id="id_master_center">
		<div id="id_master_header">
		<h2>Warring Devices</h2>
		</div>
	<div align="right" id="id_host_center_top">
		<!---->
		<ul>
		<li><img  src="images/red.gif"> <?php echo(db_fetch_cell('Select count(*) from host where status =1'));?><b> Down</b> &nbsp  &nbsp
		       <ul>
		        <?php 
		        $hostdown = db_fetch_assoc('Select id,description from host where status = 1');
		        foreach ($hostdown as $item){
		      echo('<li><a  onclick="updatehostsound('.$_REQUEST["id"].','.$item['id'].')">'.$item['description'].'</a></li>');
		     }
		        ?>
		       </ul> 
		      </li>
		      <li><img  src="images/orange.gif"> <?php echo(db_fetch_cell('Select count(*) from host where status =2'));?><b> Recovering</b> &nbsp  &nbsp  
		       <ul>
		        <?php 
		        $hostrec = db_fetch_assoc('Select id,description from host where status = 2');
		        foreach ($hostrec as $item){
		      echo('<li><a href="/../cacti/host.php?action=edit&id='.$item['id'].'" >'.$item['description'].'</a></li>');
		     }
		        ?>
		       </ul> 
		      </li>
		      <li ><img  src="images/blue.gif"> <?php echo(db_fetch_cell('Select count(*) from host where status>3'));?><b> Unknown</b> &nbsp  &nbsp &nbsp &nbsp &nbsp &nbsp  
		       <ul>
		        <?php 
		        $hostun = db_fetch_assoc('Select id,description from host where status >3');
		        foreach ($hostun as $item){
		      echo('<li><a href="/../cacti/host.php?action=edit&id='.$item['id'].'">'.$item['description'].'</a></li>');
		     }
		        ?>
		       </ul> 
		      </li>
		     </ul>
		 </div>
		</div>
	<?php 
}
function draw_showlog_views($id_show){
	$snmp_index =db_fetch_cell('SELECT snmp_index  FROM plugin_nms_interface where interface_id ="'.$id_show.'"');
	$host_id1 =db_fetch_cell('SELECT host_id  FROM plugin_nms_interface where interface_id ="'.$id_show.'"');
	$host_name =db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') as host_name FROM host where id =".$host_id1."");
	$interface_index =db_fetch_cell("SELECT CONCAT_WS('',interface_name,'  ',interface_alias)  FROM plugin_nms_interface where interface_id =".$id_show);
	$time_index = db_fetch_cell('SELECT nms_time  FROM plugin_nms_log where interface_id ="'.$id_show.'"order by log_id DESC  limit 0,1');
	?>
					<div id="id_master_header">
						<h2> Show Log</h2>
					</div>
					<div id="id_header_showlog">
						<div id="id_showlog_info_html">
    						<table id="table_showlog_html" width="100%">
  								<tr>
			    				<td width="30%">
								<table id="id_showlog_table_infor" width="100%">
									<tr align="left">
									<td><h3 class="boder_showlog_html" >Snmp_index:</h3><h4 align="center"><?php echo $snmp_index?> </h4></td>
									</tr>
									<tr>&nbsp;</tr>
									<!-- Host name -->
									<tr align="left">
									<td><h3  class="boder_showlog_html" >Interface:</h3><h4 align="center"><?php echo $interface_index?> </h4></td>
									</tr>
									<tr>&nbsp;</tr>
									<!-- Decription -->
									<tr align="left">
									<td><h3 class="boder_showlog_html">Host_name:</h3><h4 align="center"> <?php echo $host_name?> </h4></td>
									</tr>
									<tr>&nbsp;</tr>
									<!-- Time -->
									<tr align="left">
									<td><h3  class="boder_showlog_html">Time:</h3><h4 align="center"><?php echo $time_index?></h4></td>
									</tr>
								</table>
								</td>
			   					 <td width="70%"><table id="id_showlog_table_data_html" width="100%">
									<tr class="cls_master_table_title" >
										<th width="5%" scope="col">STT</th>
										<th width="8%" scope="col">Id_log</th>
										<th width="40%" scope="col">Time</th>
										<th width="25%" scope="col">Status</th>
										<th width="30%" scope="col">User</th>
									</tr>
									<?php 
										$sql_showlog = 'SELECT log_id,nms_time,nms_status,user_active  FROM plugin_nms_log where interface_id ="'.$id_show.'"order by nms_time DESC limit 0,30' ;
										$result_showlog = db_fetch_assoc($sql_showlog);
										$stt=0;
										if (empty($_GET['filter'])) {
											$status="Change";
										}
										else{
											$status =  $_GET['filter'];
										}
										if (empty($_GET['host_id'])) {
											$host_id="";
										}
										else{
											$host_id =  $_GET['host_id'];
										}
										if (empty($_GET['search'])) {
											$search="";
										}
										else{
											$search =  $_GET['search'];
										}
										//build where status query
										if(isset($_GET['filter']) or isset($_GET['host_id']) or isset($_GET['search'])){
											$base_url_show = "nms.php?run=alarm&filter=".$status."&host_id=".$host_id."&search=".$search."&id=".$_REQUEST['id'];
										}else{
											$base_url_show="nms.php?run=alarm&id=".$_REQUEST['id'];
										}
										if(isset($_GET['filter']) or isset($_GET['host_id']) or isset($_GET['search'])){
											$base_url_show1 = "nms.php?run=alarm&filter=".$status."&host_id=".$host_id."&search=".$search."&id=".$_REQUEST['id']."&tab=showlog&id_show=".$id_show."&export=show";
										}else{
											$base_url_show1 ="nms.php?run=alarm&id=".$_REQUEST['id']."&tab=showlog&id_show=".$id_show."&export=show";
										}
										foreach($result_showlog as $set) { 		
									?>
									<tr <?php if($set['nms_status']=='Down') {echo 'class="mautrangthaiDown"';}
									 elseif($set['nms_status']=='Up'){echo 'class="mautrangthaiUp"';}
									  elseif($set['nms_status']=='Unknown'){echo 'class="mautrangthaiUnknow"';}?>>
									 	<td align="center">&nbsp;<?php echo $stt++?></td>
										<td align="center">&nbsp;<?php echo $set['log_id']?></td>
										<td align="center">&nbsp;<?php echo $set['nms_time']?></td>
										<td align="center">&nbsp;<?php echo $set['nms_status']?></td>
										<td align="center">&nbsp;<?php echo $set['user_active']?></td>
										</tr>
									<?php 
									}
									?>
						<tr>
						<td>
							&nbsp;
							<input style="font-size:18px;box-shadow: 6px 4px 6px black;font-stretch: 20px;" id="btnExport" type="button" value="Export" onclick="location.href='<?php echo $base_url_show1  ?>';">
							
						</td>
						
						<td>
							&nbsp; 
							<input style="font-size:18px;box-shadow: 6px 4px 6px black;font-stretch: 20px;" id="btnClose" type="button" value="Close" onclick="location.href='<?php echo $base_url_show  ?>';">
						</td>
						</tr>
						  <tr>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						  </tr>
						  <tr>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						  </tr>
						  <tr>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
						  </tr>
					</table>
					</td>
					</tr>
				</table>
				</div>
		  	</div>
<?php 
	}
?>